from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

# 初始化Chrome浏览器
driver = webdriver.Chrome()

# 打开百度首页
driver.get("https://www.baidu.com")
driver.maximize_window()

try:
    # 获取百度Logo文本
    logo_element = driver.find_element(By.ID, "u1")
    logo_text = logo_element.text
    assert "设置" in logo_text, "Logo文本不匹配"

    # 获取搜索输入框的type属性
    search_input = driver.find_element(By.ID, "kw")
    input_type = search_input.get_attribute("type")
    assert input_type == "text", "输入框类型不匹配"

    print("断言通过，元素信息正确")

except Exception as e:
    print("获取元素信息进行断言失败：", e)

finally:
    sleep(5)  # 休眠5秒供截图
    driver.quit()